<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'header.php' ?>
<style type="text/css">
.dropdown-grade {
	margin-left: 10px;
}
.dropdown-grade li a{
	line-height: 24px;
}
#input-student {
	background-color: #FFF !important;
}
.div-submit {
	margin-top: 20px;
}
</style>
<div class="page-header">
	<h1>
		<a class="a-back" href="<?= admin_url('contents/result_grade_data/' . $majorId) ?>">
            <i class="fa fa-reply"></i>
		</a>
		<?php if(isset($resultGradeId)): ?>
			修改年级项
		<?php else: ?>
			添加年级项
		<?php endif ?>

	</h1>
</div>
<div class="col-xs-12">
	<form id="result-grade-form" class="form-horizontal">
		<!-- 考试id -->
		<input type="hidden" name="major_id" value="<?= $majorId ?>" />
        <input type="hidden" name="result_grade_id" value="<?= isset($resultGradeId) ? $resultGradeId : '' ?>" />
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">年级：</label>
            <div class="col-sm-4">
				<select class="form-control" name="grade" <?= isset($resultGradeId) ? 'disabled' : '' ?>>
					<?php foreach($grades as $grade): ?>
                        <option value="<?= $grade['id'] ?>" <?php if(isset($resultGrade['grade_id']) && $grade['id'] == $resultGrade['grade_id']): ?>selected<?php endif ?>>
                            <?= $grade['grade_name'] ?>
                        </option>
					<?php endforeach ?> 
				</select>
            </div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">是否显示年级排名：</label>
            <div class="col-sm-4">
				<select class="form-control" name="show_grade_rank">
					<option value="0" <?php if(isset($resultGrade['show_grade_rank']) && 0 == $resultGrade['show_grade_rank']): ?>selected<?php endif ?>>
						否
					</option>
					<option value="1" <?php if(isset($resultGrade['show_grade_rank']) && 1 == $resultGrade['show_grade_rank']): ?>selected<?php endif ?>>
						是
					</option>
				</select>
            </div>
		</div>
		<div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">是否显示班级排名：</label>
            <div class="col-sm-4">
				<select class="form-control" name="show_class_rank">
					<option value="0" <?php if(isset($resultGrade['show_class_rank']) && 0 == $resultGrade['show_class_rank']): ?>selected<?php endif ?>>
						否
					</option>
					<option value="1" <?php if(isset($resultGrade['show_class_rank']) && 1 == $resultGrade['show_class_rank']): ?>selected<?php endif ?>>
						是
					</option>
				</select>
            </div>
		</div>
		<div class="form-value form-group">
			<label class="col-sm-3 control-label no-padding-right">考试科目：</label>
			<div class="div-value col-sm-6">
				<select class="chosen-select form-control tag-input-style" id="subject-select" data-placeholder="选择科目" name="subject" multiple="multiple">
					<?php foreach($subjectArr as $subject): ?>
						<option value="<?= $subject['id'] ?>" <?= isset($resultGrade) && in_array($subject['id'], $resultGrade['subjectIdArr']) ? 'selected'  : '' ?>><?= $subject['lesson_name'] ?></option>
					<?php endforeach; ?>
				</select>
			</div>
		</div>
        <div class="clearfix div-submit">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="submit">
                    <i class="ace-icon fa fa-check"></i> 提交
                </button>
            </div>
        </div>
	</form>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var table = "";
	$(function(){
		// 初始化选择老师控件
		$("#select-teacher").selectTeacher({
			"multiSelect": true,
			"resultDom": $("[name=outside_teacher_ids]"),
		});
		$("#subject-select").chosen({
			search_contains: true
		}); 

		// 提交表单
		var form = $("#result-grade-form");
		var submitUrl = "<?=admin_url('contents/save_result_grade_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('contents/result_grade_data/' . $majorId)?>";
				}
			});
		})
	})
</script>